<?php include('header.php');?>
<?php
$DT = new DataTable(constant('DB_TABLE_RENT'));
$condition = "1 = 1 ";
if(isset($_REQUEST['sText']) && strlen($_REQUEST['sText']) > 0)
{
	$condition .= ' AND (';
	$condition .= sprintf("`type` like '%%%s%%'",mysql_real_escape_string($_REQUEST['sText']));
	$condition .= sprintf(" OR `size` = %s",floatval($_REQUEST['sText']));
	$condition .= sprintf(" OR `cost` = %s",floatval($_REQUEST['sText']));
	$condition .= sprintf(" OR `pre_cost` = %s",floatval($_REQUEST['sText']));
	$condition .= sprintf(" OR `pre_cost` = %s",floatval($_REQUEST['sText']));
	$condition .= sprintf(" OR `style` like '%%%s%%'",mysql_real_escape_string($_REQUEST['sText']));
	$condition .= sprintf(" OR `address` like '%%%s%%'",mysql_real_escape_string($_REQUEST['sText']));
	$condition .= sprintf(" OR `height` like '%%%s%%'",mysql_real_escape_string($_REQUEST['sText']));
	$condition .= sprintf(" OR `description` like '%%%s%%'",mysql_real_escape_string($_REQUEST['sText']));
	
	if(strpos($_REQUEST['sText'],'車位'))
	{
		$condition .= " OR `garage` = 'Y'";
	}
	/*
	$dtEqu = new DataTable(constant('DB_TABLE_EQUIPMENT'));
	$dtFur = new DataTable(constant('DB_TABLE_FURNITURE'));
	$tmpItemCondition = sprintf("`name` like '%%%s%%'",$_REQUEST['sText']);
	$tmpItemList = $dtEqu->get_list();
	*/
	$condition .= ')';
}
$totalCount = $DT->get_count($condition);

$pagesize = isset($_REQUEST['pagesize']) && intval($_REQUEST['pagesize']) > 0?$_REQUEST['pagesize']:15;
$pagenumber = isset($_REQUEST['pagenumber']) && intval($_REQUEST['pagenumber']) > 0?$_REQUEST['pagenumber']:1;
$pagecount = ceil($totalCount/$pagesize);

$offset = ($pagenumber - 1)*$pagesize;
$orderby = array('sn');
$data_list = $DT->get_list($condition,$orderby,$pagesize,$offset);
?>
<script src="js/jquery-ui-1.7.3.custom/js/jquery-1.3.2.min.js" language="JavaScript" type="text/javascript"></script>
<script language="javascript">
function search_act()
{

document.location='zlb.php?sText='+$('input[name=sText]').val();
return false;
}
</script>
<div id="maincontent">
    <div id="search"><table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="193" rowspan="2" align="right"><img src="images/searchpic.jpg" width="169" height="146" /></td>
    <td colspan="2" align="left"><img src="images/searchtitle.jpg" width="102" height="65" /></td>
    </tr>
  <tr>
    <td valign="top"><input type="text" name="sText" id="sText" value="<?php echo $_REQUEST['sText'];?>"/></td>
    <td width="136" align="right" valign="top"><a href="#" onclick="return search_act();"><img src="images/searchbutton.jpg" width="121" height="55" /></a></td>
  </tr>
  
</table>
</div>
    <div id="listmain">
      <div id="listtop"></div>
      
      <div id="listmain"><div class="carpaddinga">
      <?php 
      $dtRentType = new DataTable(constant('DB_TABLE_RENT_TYPE'));
      $renttype_list = $dtRentType->get_list('','sn');
      $renttype_table = array();
      foreach($renttype_list  as $tmprow)
      {
      	$renttype_table[$tmprow['id']] = $tmprow['name'];
      }
      foreach($data_list as $rowData)
      {
      	$type_id_list = explode(',',$rowData['type']);
      	$type_name_str = '';
      	if(is_array($type_id_list))
      	{
      		foreach($type_id_list as $type_id)
      		{
      			if(intval($type_id) > 0)
      			{
      				$type_name_str .= $renttype_table[$type_id].', ';
      			}
      		
      		}
      	}
      	
      	if(strlen($type_name_str) > 0)
      		$type_name_str = substr($type_name_str,0,-2);
      ?>
      <dl>
		<dt><a href="zlb_details.php?id=<?php echo $rowData['id'];?>"><img src="<?php echo constant('SITE_URL_PATH').$rowData['image'];?>" /></a></dt>
		<dd><a href="zlb_details.php?id=<?php echo $rowData['id'];?>"><?php echo $rowData['address'];?></a></dd>
        <dd>類型：<?php echo $type_name_str ;?></dd>
         <dd>坪數：<?php echo $rowData['size'];?>坪</dd>
         <dd>租金：<?php echo $rowData['cost'];?>元/月</dd>
	 </dl>
      <?php }?>
				
             
				<div class="clear"></div>
	  </div>
        <div class="urpagelist">
        <?php if($pagecount > 0):?>
           <?php
           		$urlParams = '';
           		if(strlen($_REQUEST['sText']) > 0)
           		{
           			$urlParams = "&sText=".urlencode($_REQUEST['sText']);
           		}
           ?>
           <ul>
            <li>第<?php echo $pagenumber;?>/<?php echo $pagecount;?>頁</li>
            <?php if($pagecount > 10):?>
            <li><a href="?pagenumber=0<?php echo $urlParams;?>">最首頁</a></li>
            <?php endif;?>
            <?php if($pagenumber > 1):?>
            <li><a href="?pagenumber=<?php echo $pagenumber -1;?><?php echo $urlParams;?>">上一頁</a></li>
            <?php endif;?>
            
            <?php
            	for($i=1;$i<$pagecount+1;$i++)
            	{
            		echo "<li><a href='?pagenumber=".$i.$urlParams."'>$i</a></li>";
            	}
            ?>
        	 <?php if($pagenumber < $pagecount):?>
            <li><a href="?pagenumber=<?php echo $pagenumber +1;?><?php echo $urlParams;?>">下一頁</a></li>
            <?php endif;?>
            <?php if($pagecount > 10):?>
            <li><a href="?pagenumber=<?php echo $pagecount;?><?php echo $urlParams;?>">最末頁</a></li>
            <?php endif;?>
            <li><a href="#">共<?php echo $totalCount;?>筆</a></li>
            </ul>
        <?php endif;?>
        </div>
                        </div>
      <div id="listbottom"></div>
    </div>
  </div>
  <?php include('bottom.php');?>